using System;
using System.Collections.Generic;
using System.Diagnostics;
using FireStarterModeller.BO;
using Habanero.Base.Exceptions;

namespace FireStarterModeller.Logic
{
    public class UIViewCreator
    {
        /// <summary>
        /// This is currently not being used.
        /// This is planned to be used as follows.
        /// The wizard for creating the UI is to be modified to be able to edit the UI as well.
        /// If this wizard is now being used to Create a UI then this 
        /// Class should be used to Create the UIView with the properties we think should be on the UI.
        /// We base our assumption of what should be on the UI on heuristics like the IDProp and FKProps
        /// should not be on the UI if they are Guids.
        /// The ID Prop since it is meaningless and the FKProp since we are now implementing these on
        /// forms using the Relationship instead of the Prop.
        /// </summary>
        /// <param name="dmClass"></param>
        /// <returns></returns>
        public UIView CreateUIView(DMClass dmClass)
        {
            if (dmClass == null) throw new ArgumentNullException("dmClass");
            if (dmClass.Solution == null)
            {
                throw new HabaneroArgumentException
                    ("dmClass.Solution", "You cannot create a UIView for a "
                    + "DMClass that is not associated with a Solution - (DMClass '" + dmClass.ClassNameBO + "')");
            }
            UIView view = new UIView {Class = dmClass};
            UIFormCreator boEditorCreator = new UIFormCreator();
            UIFormInfo boEditor = boEditorCreator.CreateUIForm(dmClass);
            view.UIFormInfo = boEditor;

            UIGridCreator gridCreator = new UIGridCreator();
            UIGridInfo gridInfo = gridCreator.CreateGrid(dmClass, dmClass.Properties);
            view.UIGridInfo = gridInfo;

            UIGridFilterCreator gridFilterCreator = new UIGridFilterCreator((DMSolution)dmClass.Solution);
            UIGridFilter gridFilterInfo = gridFilterCreator.CreateUIGridFilter(dmClass.Properties);
            gridInfo.UIGridFilter = gridFilterInfo;
            return view;
        }
    }
}